package com.zl.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.system.comm.util.CheckUtil;
import com.system.comm.util.JsonUtils;
import com.system.common.pojo.BisCustomUser;
import com.system.common.pojo.BisShop;
import com.zl.service.ZlBisNurseProjectService;
import com.zl.service.ZlBisShopService;

@Controller
@RequestMapping("shop")
public class wechatShopController {
	@Autowired
	private ZlBisShopService zlBisShopService;
	@Autowired
	private ZlBisNurseProjectService zlBisNurseProjectService;
	@RequestMapping("goFindShop")
	public String goFindShop(String returnType,String projectId,Model model,HttpServletRequest request){
		
		if ("1".equals(returnType)) {
			String typeName="";
			try {
				 typeName = java.net.URLDecoder.decode(request.getParameter("typeName"), "utf-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			model.addAttribute("typeName", typeName);
			model.addAttribute("projectId", projectId);
			return "/wechat/shop/selectShop";
		}else {
			return "wechat/shop/findShop";
		}
		
		
	}
	
	@RequestMapping("showShopDetail")
	public String showShopDetail(String shop_id,HttpServletRequest request,
			HttpServletResponse response,HttpSession session){
		zlBisNurseProjectService.selectByExample(null);
		
	
		return "wechat/shop/showShopDetail";
	}
	
	@RequestMapping("listShopCollect")
    public String listShopCollect(HttpServletRequest request, 
			HttpServletResponse response,HttpSession session,Model model){
		BisCustomUser bisCustomUser= CheckUtil.getUserSession(session);
		List<BisShop> shopList=zlBisShopService.ShopCollect(bisCustomUser.getCustomUserId());
		if (shopList!=null) {
			model.addAttribute("show_data", "1");
		}else {
			model.addAttribute("show_data", "0");
		}
		model.addAttribute("shopList", shopList);
    	return "wechat/my/myShopCollect";
    	
    }
	
	@RequestMapping("searchShop")
	public void searchShop(HttpServletResponse response,Model model,String typeName){
		Map<String, Object> map=new HashMap<>();
		map.put("typeName", typeName);
		List<BisShop> shopLists=zlBisShopService.selectByExample(map);
		
		String shopList=JsonUtils.toJson(shopLists);
		try {
			PrintWriter p=response.getWriter();
			p.write(shopList);
			p.close();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	@RequestMapping("saveAppSubscribeOrder")
	public void saveAppSubscribeOrder(HttpServletResponse response,HttpSession session,String projectId,String shopId,String subscribeTime,String subscribeDeposit){
		
		BisCustomUser bisCustomUser=CheckUtil.getUserSession(session);
		Map<String, Object> map=new HashMap<>();
		map.put("projectId", projectId);
		map.put("subscribeDeposit", subscribeDeposit);
		map.put("shopId", shopId);
		map.put("subscribeTime", subscribeTime);
		map.put("bisCustomUser", bisCustomUser);
		Map<String, Object> mapp=zlBisShopService.shopBeauty(map);
		String str=JsonUtils.toJson(mapp);
		CheckUtil.responseW(response, str);
		
	}
	
	

}
